package com.wy.servlet;

import com.wy.Listener.ActionListener;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/a01.do")
public class AListener extends BaseServlet {

    protected void req(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("req", "req1");
        req.setAttribute("req", "req2");
        req.removeAttribute("req");
    }

    protected void ses(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        session.setAttribute("ses", "ses1");
        session.setAttribute("ses", "ses2");
        session.removeAttribute("ses");
    }

    protected void con(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = req.getServletContext();
        servletContext.setAttribute("con", "con1");
        servletContext.setAttribute("con", "con2");
        servletContext.removeAttribute("con");
    }

    protected void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getSession().setAttribute("s",new ActionListener("aaa"));
    }

    protected void get(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(req.getSession().getAttribute("s"));
    }

}
